using System;
using System.Collections.Generic;
using System.Linq;
namespace TemplateWeb.Controllers
{
	#region using
	using System;
	using System.Web.Mvc;
	using System.Web.Security;
	using System.Collections.Generic;
	using TemplateWeb.Models.ViewModels;
	using TemplateWeb.Models.Repositories;
	using TemplateWeb.Helpers;
	using TemplateWeb.Models;
	using System.IO;
	using System.Web;
	#endregion
	public abstract class BaseController : Controller
	{
		protected GoiThietKeWebRepository _repGoiThietKeWeb = new GoiThietKeWebRepository();
		protected ThongTinWebsiteRepository _repThongTinWebsite = new ThongTinWebsiteRepository();
		protected LoaiTinTucRepository _repLoaiTinTuc = new LoaiTinTucRepository();
		protected KhachHangRepository _repKhachHang = new KhachHangRepository();
		protected TinTucRepository _repTinTuc = new TinTucRepository();
		protected BinhLuanTinTucRepository _repBinhLuanTinTuc = new BinhLuanTinTucRepository();
		protected PhanMemQuanLyRepository _repPhanMemQuanLy = new PhanMemQuanLyRepository();
		protected VungQuangCaoRepository _repVungQuangCao = new VungQuangCaoRepository();
		protected QuangCaoRepository _repQuangCao = new QuangCaoRepository();
		protected ChuongTrinhKhuyenMaiRepository _repChuongTrinhKhuyenMai = new ChuongTrinhKhuyenMaiRepository();
		protected ThongKeRepository _repThongKe = new ThongKeRepository();
		protected LoaiVideoRepository _repLoaiVideo = new LoaiVideoRepository();
		protected AlbumRepository _repAlbum = new AlbumRepository();
		protected VideoRepository _repVideo = new VideoRepository();
		protected PhanHoiRepository _repPhanHoi = new PhanHoiRepository();
		protected HopThuRepository _repHopThu = new HopThuRepository();
		protected BinhLuanVideoRepository _repBinhLuanVideo = new BinhLuanVideoRepository();
		protected DanhMucWebRepository _repDanhMucWeb = new DanhMucWebRepository();
		protected MauThietKeRepository _repMauThietKe = new MauThietKeRepository();
		protected NguoiDungRepository _repNguoiDung = new NguoiDungRepository();
        protected ThietKeWebRepository _repThietKeWeb = new ThietKeWebRepository();
        protected KhachHangLamPhanMemRepository _repKhachHangLamPhanMem = new KhachHangLamPhanMemRepository();

		protected string RenderPartialViewToString()
		{
			return RenderPartialViewToString(null, null);
		}

		protected string RenderPartialViewToString(string viewName)
		{
			return RenderPartialViewToString(viewName, null);
		}

		protected string RenderPartialViewToString(string viewName, object model)
		{
			if (string.IsNullOrEmpty(viewName))
				viewName = ControllerContext.RouteData.GetRequiredString("action");
			ViewData.Model = model;
			using (StringWriter sw = new StringWriter())
			{
				ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
				ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
				viewResult.View.Render(viewContext, sw);
				return sw.GetStringBuilder().ToString();
			}
		}


		public GroupViewModel CreateViewModel(DataTransferViewModel dataTransfer)
		{
			GroupViewModel viewModel = new GroupViewModel();
            if (dataTransfer.EnumViewModelType.ToString().Contains("ADMIN"))
            {
                viewModel.DanhMucWebModel = RetrieveDanhMucWebViewModel(dataTransfer);
                viewModel.LoaiTinTucModel = RetrieveLoaiTinTucViewModel(dataTransfer);
                viewModel.LoaiVideoModel = RetrieveLoaiVideoViewModel(dataTransfer);
                viewModel.VungQuangCaoModel = RetrieveVungQuangCaoViewModel(dataTransfer);
            }
            else if (dataTransfer.EnumViewModelType.ToString().Contains("HOME"))
            {
                viewModel.ThongTinWebsiteModel = RetrieveThongTinWebsiteViewModel(dataTransfer);
                viewModel.LoaiTinTucModel = RetrieveLoaiTinTucViewModel(dataTransfer);
                viewModel.LoaiVideoModel = RetrieveLoaiVideoViewModel(dataTransfer);
                viewModel.SanPhamMoiViewModel = RetrieveTinTucSanPhamMoiViewModel(dataTransfer);
            }
			switch (dataTransfer.EnumViewModelType)
			{
				case EnumViewModel.ADMIN_DETAILOF_GOITHIETKEWEB:
                    viewModel.GoiThietKeWebModel = RetrieveDetailOfGoiThietKeWebViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_DETAILOF_THONGTINWEBSITE:
                    viewModel.ThongTinWebsiteModel = RetrieveDetailOfThongTinWebsiteViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_DETAILOF_KHACHHANG:
                    viewModel.KhachHangModel = RetrieveDetailOfKhachHangViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_DETAILOF_TINTUC:
                    viewModel.TinTucModel = RetrieveDetailOfTinTucViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_DETAILOF_NGUOIDUNG:
                    viewModel.NguoiDungModel = RetrieveDetailOfNguoiDungViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_DETAILOF_PHANMEMQUANLY:
                    viewModel.PhanMemQuanLyModel = RetrieveDetailOfPhanMemQuanLyViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_DETAILOF_QUANGCAO:
                    viewModel.QuangCaoModel = RetrieveQuangCaoViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_DETAILOF_CHUONGTRINHKHUYENMAI:
                    viewModel.ChuongTrinhKhuyenMaiModel = RetrieveDetailOfChuongTrinhKhuyenMaiViewModel(dataTransfer);
					break;
                case EnumViewModel.ADMIN_DETAILOF_ALBUM:
                    viewModel.AlbumModel = RetrieveDetailOfAlbumViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_DETAILOF_VIDEO:
                    viewModel.VideoModel = RetrieveDetailOfVideoViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_DETAILOF_HOPTHU:
					break;
				case EnumViewModel.ADMIN_DETAILOF_DANHMUCWEB:
                    viewModel.DetailOfDanhMucWebModel = RetrieveDetailOfDanhMucWebViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_DETAILOF_MAUTHIETKE:
                    viewModel.MauThietKeModel = RetrieveMauThietKeViewModel(dataTransfer);
					break;
                case EnumViewModel.ADMIN_DETAILOF_THIETKEWEB:
                    viewModel.ThietKeWebModel = RetrieveThietKeWebViewModel(dataTransfer);
                    break;
                case EnumViewModel.ADMIN_DETAILOF_KHACHHANGLAMPHANMEM:
                    viewModel.KhachHangLamPhanMemModel = RetrieveDetailOfKhachHangLamPhanMemViewModel(dataTransfer);
                    break;
				case EnumViewModel.ADMIN_GOITHIETKEWEB:
                    viewModel.GoiThietKeWebModel = RetrieveGoiThietKeWebViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_THONGTINWEBSITE:
                    viewModel.ThongTinWebsiteModel = RetrieveThongTinWebsiteViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_LOAITINTUC:
					break;
				case EnumViewModel.ADMIN_KHACHHANG:
                    viewModel.KhachHangModel = RetrieveKhachHangViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_TINTUC:
                    viewModel.TinTucModel = RetrieveTinTucViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_BINHLUANTINTUC:
					break;
				case EnumViewModel.ADMIN_NGUOIDUNG:
                    viewModel.NguoiDungModel = RetrieveNguoiDungViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_PHANMEMQUANLY:
                    viewModel.PhanMemQuanLyModel = RetrievePhanMemQuanLyViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_VUNGQUANGCAO:
					break;
				case EnumViewModel.ADMIN_QUANGCAO:
                    viewModel.QuangCaoModel = RetrieveQuangCaoViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_CHUONGTRINHKHUYENMAI:
                    viewModel.ChuongTrinhKhuyenMaiModel = RetrieveChuongTrinhKhuyenMaiViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_THONGKE:
					break;
				case EnumViewModel.ADMIN_LOAIVIDEO:
					break;
				case EnumViewModel.ADMIN_ALBUM:
                    viewModel.AlbumModel = RetrieveAlbumViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_VIDEO:
                    viewModel.VideoModel = RetrieveVideoViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_PHANHOI:
                    viewModel.PhanHoiModel = RetrievePhanHoiViewModel(dataTransfer);
                    viewModel.HopThuModel = RetrieveHopThuViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_HOPTHU:
                    viewModel.HopThuModel = RetrieveHopThuViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_BINHLUANVIDEO:
					break;
				case EnumViewModel.ADMIN_DANHMUCWEB:
					break;
				case EnumViewModel.ADMIN_MAUTHIETKE:
                    viewModel.MauThietKeModel = RetrieveMauThietKeViewModel(dataTransfer);
					break;
                case EnumViewModel.ADMIN_THIETKEWEB:
                    viewModel.ThietKeWebModel = RetrieveThietKeWebViewModel(dataTransfer);
                    break;
                case EnumViewModel.ADMIN_KHACHHANGLAMPHANMEM:
                    viewModel.KhachHangLamPhanMemModel = RetrieveKhachHangLamPhanMemViewModel(dataTransfer);
                    break;

                // HOME
                case EnumViewModel.HOME_INDEX:
                    viewModel.GoiThietKeWebModel = RetrieveGoiThietKeWebViewModel(dataTransfer);
                    viewModel.KhachHangModel = RetrieveKhachHangViewModel(dataTransfer);
                    viewModel.ChuongTrinhKhuyenMaiModel = RetrieveChuongTrinhKhuyenMaiViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_GIOITHIEU:
                    break;
                case EnumViewModel.HOME_THIETKEWEB:
                    viewModel.ThietKeWebModel = RetrieveThietKeWebViewModel(dataTransfer);
                    viewModel.DanhMucWebModel = RetrieveDanhMucWebViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_CHITIETDANHMUCWEB:
                    viewModel.DetailOfDanhMucWebModel = RetrieveDetailOfDanhMucWebViewModel(dataTransfer);
                    viewModel.MauThietKeModel = RetrieveMauThietKeViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_PHANMEMQUANLY:
                    viewModel.PhanMemQuanLyModel = RetrievePhanMemQuanLyViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_CHITIETPHANMEMQUANLY:
                    viewModel.PhanMemQuanLyModel = RetrieveDetailOfPhanMemQuanLyViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_GOIDICHVU:
                    viewModel.GoiThietKeWebModel = RetrieveDetailOfGoiThietKeWebViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_KHACHHANG:
                    viewModel.KhachHangModel = RetrieveKhachHangViewModel(dataTransfer);
                    viewModel.KhachHangLamPhanMemModel = RetrieveKhachHangLamPhanMemViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_TINTUC:
                    viewModel.TinTucModel = RetrieveTinTucViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_CHITIETTINTUC:
                    viewModel.TinTucModel = RetrieveDetailOfTinTucViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_ALBUM:
                    viewModel.AlbumModel = RetrieveAlbumViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_VIDEO:
                    viewModel.AlbumModel = RetrieveDetailOfAlbumViewModel(dataTransfer);
                    viewModel.VideoModel = RetrieveVideoViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_SHOWVIDEO:
                    viewModel.AlbumModel = RetrieveDetailOfAlbumViewModel2(dataTransfer);
                    viewModel.VideoModel = RetrieveDetailOfVideoViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_KHACHHANGLAMPHANMEM:
                    viewModel.KhachHangLamPhanMemModel = RetrieveDetailOfKhachHangLamPhanMemViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_CHUONGTRINHKHUYEMAI:
                    viewModel.ChuongTrinhKhuyenMaiModel = RetrieveDetailOfChuongTrinhKhuyenMaiViewModel(dataTransfer);
                    break;
			}
			return viewModel;
		}

		public bool SendingMail(string subject, string emailContent, string to)
		{
			bool result = false;
			try
			{
                var thongtincongty = RetrieveThongTinWebsiteViewModel(new DataTransferViewModel());
                if (thongtincongty.GetModel.LstObjModel.Count > 0)
                {
                    WebConfiguration.EmailLienHe = thongtincongty.GetModel.LstObjModel[0].EmailCongTy;
                    WebConfiguration.PasswordEmailLienHe = Encryption.Decrypt(thongtincongty.GetModel.LstObjModel[0].MatKhauEmailCongTy);
                    emailContent = emailContent.Replace("[EmailLienHe]", WebConfiguration.EmailLienHe);

                    System.Net.Mail.SmtpClient mailclient = new System.Net.Mail.SmtpClient();
                    System.Net.NetworkCredential auth = new System.Net.NetworkCredential(WebConfiguration.EmailLienHe, WebConfiguration.PasswordEmailLienHe);
                    mailclient.Host = WebConfiguration.MailServer;
                    mailclient.EnableSsl = true;
                    mailclient.UseDefaultCredentials = true;
                    mailclient.Credentials = auth;
                    System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(WebConfiguration.EmailLienHe, to);
                    mm.Subject = subject;
                    mm.IsBodyHtml = true;
                    mm.Body = emailContent;
                    mailclient.Send(mm);
                    result = true;
                }
			}
			catch
			{
				result = false;
			}
			return result;
		}

		public GoiThietKeWebViewModel RetrieveGoiThietKeWebViewModel(DataTransferViewModel dataTransfer)
		{
			return new GoiThietKeWebViewModel
			{
				GetModel = new GetGoiThietKeWebViewModel
				{
					LstObjModel = _repGoiThietKeWeb.SelectAll(),
					TotalItem = _repGoiThietKeWeb.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddGoiThietKeWebViewModel
				{
				},
				EditModel = new EditGoiThietKeWebViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public ThongTinWebsiteViewModel RetrieveThongTinWebsiteViewModel(DataTransferViewModel dataTransfer)
		{
			return new ThongTinWebsiteViewModel
			{
				GetModel = new GetThongTinWebsiteViewModel
				{
					LstObjModel = _repThongTinWebsite.SelectAll(),
					TotalItem = _repThongTinWebsite.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddThongTinWebsiteViewModel
				{
				},
				EditModel = new EditThongTinWebsiteViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public LoaiTinTucViewModel RetrieveLoaiTinTucViewModel(DataTransferViewModel dataTransfer)
		{
			return new LoaiTinTucViewModel
			{
				GetModel = new GetLoaiTinTucViewModel
				{
					LstObjModel = _repLoaiTinTuc.SelectAll(),
					TotalItem = _repLoaiTinTuc.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddLoaiTinTucViewModel
				{
				},
				EditModel = new EditLoaiTinTucViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public KhachHangViewModel RetrieveKhachHangViewModel(DataTransferViewModel dataTransfer)
		{
			return new KhachHangViewModel
			{
				GetModel = new GetKhachHangViewModel
				{
					LstObjModel = _repKhachHang.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumKhachHangPerPage),
					TotalItem = _repKhachHang.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddKhachHangViewModel
				{
				},
				EditModel = new EditKhachHangViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public TinTucViewModel RetrieveTinTucViewModel(DataTransferViewModel dataTransfer)
		{
			List<TinTuc> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDLoaiTinTuc != -1)
			{
				lst = _repTinTuc.SelectByIDLoaiTinTuc(dataTransfer.IDLoaiTinTuc, dataTransfer.CurrentPage, WebConfiguration.NumTinTucPerPage);
				totalitem = _repTinTuc.GetTotalItemByIDLoaiTinTuc(dataTransfer.IDLoaiTinTuc);
			}
			else
			{
				lst = _repTinTuc.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumTinTucPerPage);
				totalitem = _repTinTuc.GetTotalItem();
			}
			return new TinTucViewModel
			{
				GetModel = new GetTinTucViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddTinTucViewModel
				{
				},
				EditModel = new EditTinTucViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new TinTucReferKeys()
				{
					IDLoaiTinTuc = dataTransfer.IDLoaiTinTuc,
				},
				InfoText = dataTransfer.InfoText
			};
		}

        public TinTucViewModel RetrieveTinTucSanPhamMoiViewModel(DataTransferViewModel dataTransfer)
        {
            var lst = _repTinTuc.SelectTinTucSanPhamMoi();
            var totalitem = lst.Count;
            return new TinTucViewModel
            {
                GetModel = new GetTinTucViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddTinTucViewModel
                {
                },
                EditModel = new EditTinTucViewModel
                {
                    ID = dataTransfer.IntID,
                },
                ReferKeys = new TinTucReferKeys()
                {
                    IDLoaiTinTuc = dataTransfer.IDLoaiTinTuc,
                },
                InfoText = dataTransfer.InfoText
            };
        }

		public BinhLuanTinTucViewModel RetrieveBinhLuanTinTucViewModel(DataTransferViewModel dataTransfer)
		{
			List<BinhLuanTinTuc> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDTinTuc != -1)
			{
				lst = _repBinhLuanTinTuc.SelectByIDTinTuc(dataTransfer.IDTinTuc, dataTransfer.CurrentPage, WebConfiguration.NumBinhLuanTinTucPerPage);
				totalitem = _repBinhLuanTinTuc.GetTotalItemByIDTinTuc(dataTransfer.IDTinTuc);
			}
			else
			{
				lst = _repBinhLuanTinTuc.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumBinhLuanTinTucPerPage);
				totalitem = _repBinhLuanTinTuc.GetTotalItem();
			}
			return new BinhLuanTinTucViewModel
			{
				GetModel = new GetBinhLuanTinTucViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddBinhLuanTinTucViewModel
				{
				},
				EditModel = new EditBinhLuanTinTucViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new BinhLuanTinTucReferKeys()
				{
					IDTinTuc = dataTransfer.IDTinTuc,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public PhanMemQuanLyViewModel RetrievePhanMemQuanLyViewModel(DataTransferViewModel dataTransfer)
		{
			return new PhanMemQuanLyViewModel
			{
				GetModel = new GetPhanMemQuanLyViewModel
				{
					LstObjModel = _repPhanMemQuanLy.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumPhanMemQuanLyPerPage),
					TotalItem = _repPhanMemQuanLy.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddPhanMemQuanLyViewModel
				{
				},
				EditModel = new EditPhanMemQuanLyViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public VungQuangCaoViewModel RetrieveVungQuangCaoViewModel(DataTransferViewModel dataTransfer)
		{
			return new VungQuangCaoViewModel
			{
				GetModel = new GetVungQuangCaoViewModel
				{
					LstObjModel = _repVungQuangCao.SelectAll(),
					TotalItem = _repVungQuangCao.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddVungQuangCaoViewModel
				{
				},
				EditModel = new EditVungQuangCaoViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public QuangCaoViewModel RetrieveQuangCaoViewModel(DataTransferViewModel dataTransfer)
		{
			List<QuangCao> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDVungQuangCao != -1)
			{
				lst = _repQuangCao.SelectByIDVungQuangCao(dataTransfer.IDVungQuangCao, dataTransfer.CurrentPage, WebConfiguration.NumQuangCaoPerPage);
				totalitem = _repQuangCao.GetTotalItemByIDVungQuangCao(dataTransfer.IDVungQuangCao);
			}
			else
			{
				lst = _repQuangCao.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumQuangCaoPerPage);
				totalitem = _repQuangCao.GetTotalItem();
			}
			return new QuangCaoViewModel
			{
				GetModel = new GetQuangCaoViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddQuangCaoViewModel
				{
				},
				EditModel = new EditQuangCaoViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new QuangCaoReferKeys()
				{
					IDVungQuangCao = dataTransfer.IDVungQuangCao,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public ChuongTrinhKhuyenMaiViewModel RetrieveChuongTrinhKhuyenMaiViewModel(DataTransferViewModel dataTransfer)
		{
			return new ChuongTrinhKhuyenMaiViewModel
			{
				GetModel = new GetChuongTrinhKhuyenMaiViewModel
				{
					LstObjModel = _repChuongTrinhKhuyenMai.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumChuongTrinhKhuyenMaiPerPage),
					TotalItem = _repChuongTrinhKhuyenMai.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddChuongTrinhKhuyenMaiViewModel
				{
				},
				EditModel = new EditChuongTrinhKhuyenMaiViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public ThongKeViewModel RetrieveThongKeViewModel(DataTransferViewModel dataTransfer)
		{
			return new ThongKeViewModel
			{
				GetModel = new GetThongKeViewModel
				{
					LstObjModel = _repThongKe.SelectAll(),
					TotalItem = _repThongKe.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddThongKeViewModel
				{
				},
				EditModel = new EditThongKeViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public LoaiVideoViewModel RetrieveLoaiVideoViewModel(DataTransferViewModel dataTransfer)
		{
			return new LoaiVideoViewModel
			{
				GetModel = new GetLoaiVideoViewModel
				{
					LstObjModel = _repLoaiVideo.SelectAll(),
					TotalItem = _repLoaiVideo.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddLoaiVideoViewModel
				{
				},
				EditModel = new EditLoaiVideoViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public AlbumViewModel RetrieveAlbumViewModel(DataTransferViewModel dataTransfer)
		{
			List<Album> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDLoaiVideo != -1)
			{
				lst = _repAlbum.SelectByIDLoaiVideo(dataTransfer.IDLoaiVideo, dataTransfer.CurrentPage, WebConfiguration.NumAlbumPerPage);
				totalitem = _repAlbum.GetTotalItemByIDLoaiVideo(dataTransfer.IDLoaiVideo);
			}
			else
			{
				lst = _repAlbum.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumAlbumPerPage);
				totalitem = _repAlbum.GetTotalItem();
			}
			return new AlbumViewModel
			{
				GetModel = new GetAlbumViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddAlbumViewModel
				{
				},
				EditModel = new EditAlbumViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new AlbumReferKeys()
				{
					IDLoaiVideo = dataTransfer.IDLoaiVideo,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public VideoViewModel RetrieveVideoViewModel(DataTransferViewModel dataTransfer)
		{
			List<Video> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDAlbum != -1)
			{
				lst = _repVideo.SelectByIDAlbum(dataTransfer.IDAlbum, dataTransfer.CurrentPage, WebConfiguration.NumVideoPerPage);
				totalitem = _repVideo.GetTotalItemByIDAlbum(dataTransfer.IDAlbum);
			}
			else
			{
				lst = _repVideo.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumVideoPerPage);
				totalitem = _repVideo.GetTotalItem();
			}
			return new VideoViewModel
			{
				GetModel = new GetVideoViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddVideoViewModel
				{
				},
				EditModel = new EditVideoViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new VideoReferKeys()
				{
					IDAlbum = dataTransfer.IDAlbum,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public PhanHoiViewModel RetrievePhanHoiViewModel(DataTransferViewModel dataTransfer)
		{
			List<PhanHoi> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDHopThu != -1)
			{
				lst = _repPhanHoi.SelectByIDHopThu(dataTransfer.IDHopThu, dataTransfer.CurrentPage, WebConfiguration.NumPhanHoiPerPage);
				totalitem = _repPhanHoi.GetTotalItemByIDHopThu(dataTransfer.IDHopThu);
			}
			else
			{
				lst = _repPhanHoi.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumPhanHoiPerPage);
				totalitem = _repPhanHoi.GetTotalItem();
			}
			return new PhanHoiViewModel
			{
				GetModel = new GetPhanHoiViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddPhanHoiViewModel
				{
				},
				EditModel = new EditPhanHoiViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new PhanHoiReferKeys()
				{
					IDHopThu = dataTransfer.IDHopThu,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public HopThuViewModel RetrieveHopThuViewModel(DataTransferViewModel dataTransfer)
		{
			return new HopThuViewModel
			{
				GetModel = new GetHopThuViewModel
				{
					LstObjModel = _repHopThu.SelectAll(),
					TotalItem = _repHopThu.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddHopThuViewModel
				{
				},
				EditModel = new EditHopThuViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public BinhLuanVideoViewModel RetrieveBinhLuanVideoViewModel(DataTransferViewModel dataTransfer)
		{
			List<BinhLuanVideo> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDAlbum != -1)
			{
				lst = _repBinhLuanVideo.SelectByIDAlbum(dataTransfer.IDAlbum, dataTransfer.CurrentPage, WebConfiguration.NumBinhLuanVideoPerPage);
				totalitem = _repBinhLuanVideo.GetTotalItemByIDAlbum(dataTransfer.IDAlbum);
			}
			else
			{
				lst = _repBinhLuanVideo.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumBinhLuanVideoPerPage);
				totalitem = _repBinhLuanVideo.GetTotalItem();
			}
			return new BinhLuanVideoViewModel
			{
				GetModel = new GetBinhLuanVideoViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddBinhLuanVideoViewModel
				{
				},
				EditModel = new EditBinhLuanVideoViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new BinhLuanVideoReferKeys()
				{
					IDAlbum = dataTransfer.IDAlbum,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public DanhMucWebViewModel RetrieveDanhMucWebViewModel(DataTransferViewModel dataTransfer)
		{
			return new DanhMucWebViewModel
			{
				GetModel = new GetDanhMucWebViewModel
				{
					LstObjModel = _repDanhMucWeb.SelectAll(),
					TotalItem = _repDanhMucWeb.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddDanhMucWebViewModel
				{
				},
				EditModel = new EditDanhMucWebViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public MauThietKeViewModel RetrieveMauThietKeViewModel(DataTransferViewModel dataTransfer)
		{
			List<MauThietKe> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDDanhMucWeb != -1)
			{
				lst = _repMauThietKe.SelectByIDDanhMucWeb(dataTransfer.IDDanhMucWeb, dataTransfer.CurrentPage, WebConfiguration.NumMauThietKePerPage);
				totalitem = _repMauThietKe.GetTotalItemByIDDanhMucWeb(dataTransfer.IDDanhMucWeb);
			}
			else
			{
				lst = _repMauThietKe.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumMauThietKePerPage);
				totalitem = _repMauThietKe.GetTotalItem();
			}
			return new MauThietKeViewModel
			{
				GetModel = new GetMauThietKeViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddMauThietKeViewModel
				{
				},
				EditModel = new EditMauThietKeViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new MauThietKeReferKeys()
				{
					IDDanhMucWeb = dataTransfer.IDDanhMucWeb,
				},
				InfoText = dataTransfer.InfoText
			};
		}

        public NguoiDungViewModel RetrieveManagerViewModel(DataTransferViewModel dataTransfer)
        {
            var lst = _repNguoiDung.SelectManagers();
            return new NguoiDungViewModel
            {
                GetModel = new GetNguoiDungViewModel
                {
                    LstObjModel = _repNguoiDung.SelectManagers(),
                    TotalItem = lst.Count,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddNguoiDungViewModel
                {
                },
                EditModel = new EditNguoiDungViewModel
                {
                    ID = dataTransfer.GuidID,
                }
            };
        }

		public NguoiDungViewModel RetrieveNguoiDungViewModel(DataTransferViewModel dataTransfer)
		{
			return new NguoiDungViewModel
			{
				GetModel = new GetNguoiDungViewModel
				{
					LstObjModel = _repNguoiDung.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumNguoiDungPerPage, dataTransfer.Role),
					TotalItem = _repNguoiDung.GetTotalItem(dataTransfer.Role),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddNguoiDungViewModel
				{
				},
				EditModel = new EditNguoiDungViewModel
				{
					ID = dataTransfer.GuidID,
				}
			};
		}

		public GoiThietKeWebViewModel RetrieveDetailOfGoiThietKeWebViewModel(DataTransferViewModel dataTransfer)
		{
			return new GoiThietKeWebViewModel
			{
				GetModel = new GetGoiThietKeWebViewModel
				{
					LstObjModel = _repGoiThietKeWeb.RetrieveByID(dataTransfer.IntID)
				},
				EditModel = new EditGoiThietKeWebViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}
		public ThongTinWebsiteViewModel RetrieveDetailOfThongTinWebsiteViewModel(DataTransferViewModel dataTransfer)
		{
			return new ThongTinWebsiteViewModel
			{
				GetModel = new GetThongTinWebsiteViewModel
				{
					LstObjModel = _repThongTinWebsite.RetrieveByID(dataTransfer.IntID)
				},
				EditModel = new EditThongTinWebsiteViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}
		public KhachHangViewModel RetrieveDetailOfKhachHangViewModel(DataTransferViewModel dataTransfer)
		{
			return new KhachHangViewModel
			{
				GetModel = new GetKhachHangViewModel
				{
					LstObjModel = _repKhachHang.RetrieveByID(dataTransfer.IntID)
				},
				EditModel = new EditKhachHangViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}
		public TinTucViewModel RetrieveDetailOfTinTucViewModel(DataTransferViewModel dataTransfer)
		{
			return new TinTucViewModel
			{
				GetModel = new GetTinTucViewModel
				{
					LstObjModel = _repTinTuc.RetrieveByID(dataTransfer.IntID)
				},
				EditModel = new EditTinTucViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}
		public NguoiDungViewModel RetrieveDetailOfNguoiDungViewModel(DataTransferViewModel dataTransfer)
		{
			return new NguoiDungViewModel
			{
				GetModel = new GetNguoiDungViewModel
				{
					LstObjModel = _repNguoiDung.RetrieveByID(dataTransfer.GuidID)
				},
				EditModel = new EditNguoiDungViewModel
				{
					ID = dataTransfer.GuidID,
				},
				InfoText = dataTransfer.InfoText
			};
		}
		public PhanMemQuanLyViewModel RetrieveDetailOfPhanMemQuanLyViewModel(DataTransferViewModel dataTransfer)
		{
			return new PhanMemQuanLyViewModel
			{
				GetModel = new GetPhanMemQuanLyViewModel
				{
					LstObjModel = _repPhanMemQuanLy.RetrieveByID(dataTransfer.IntID)
				},
				EditModel = new EditPhanMemQuanLyViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}
		public QuangCaoViewModel RetrieveDetailOfQuangCaoViewModel(DataTransferViewModel dataTransfer)
		{
			return new QuangCaoViewModel
			{
				GetModel = new GetQuangCaoViewModel
				{
					LstObjModel = _repQuangCao.RetrieveByID(dataTransfer.IntID)
				},
				EditModel = new EditQuangCaoViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}
		public ChuongTrinhKhuyenMaiViewModel RetrieveDetailOfChuongTrinhKhuyenMaiViewModel(DataTransferViewModel dataTransfer)
		{
			return new ChuongTrinhKhuyenMaiViewModel
			{
				GetModel = new GetChuongTrinhKhuyenMaiViewModel
				{
					LstObjModel = _repChuongTrinhKhuyenMai.RetrieveByID(dataTransfer.IntID)
				},
				EditModel = new EditChuongTrinhKhuyenMaiViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}
		public AlbumViewModel RetrieveDetailOfAlbumViewModel(DataTransferViewModel dataTransfer)
		{
			return new AlbumViewModel
			{
				GetModel = new GetAlbumViewModel
				{
					LstObjModel = _repAlbum.RetrieveByID(dataTransfer.IntID)
				},
				EditModel = new EditAlbumViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}
        public AlbumViewModel RetrieveDetailOfAlbumViewModel2(DataTransferViewModel dataTransfer)
        {
            return new AlbumViewModel
            {
                GetModel = new GetAlbumViewModel
                {
                    LstObjModel = _repAlbum.RetrieveByID(dataTransfer.IDAlbum)
                },
                EditModel = new EditAlbumViewModel
                {
                    ID = dataTransfer.IntID,
                },
                InfoText = dataTransfer.InfoText
            };
        }
		public VideoViewModel RetrieveDetailOfVideoViewModel(DataTransferViewModel dataTransfer)
		{
			return new VideoViewModel
			{
				GetModel = new GetVideoViewModel
				{
					LstObjModel = _repVideo.RetrieveByID(dataTransfer.IntID)
				},
				EditModel = new EditVideoViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public DanhMucWebViewModel RetrieveDetailOfDanhMucWebViewModel(DataTransferViewModel dataTransfer)
		{
			return new DanhMucWebViewModel
			{
				GetModel = new GetDanhMucWebViewModel
				{
					LstObjModel = _repDanhMucWeb.RetrieveByID(dataTransfer.IntID)
				},
				EditModel = new EditDanhMucWebViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}
		public MauThietKeViewModel RetrieveDetailOfMauThietKeViewModel(DataTransferViewModel dataTransfer)
		{
			return new MauThietKeViewModel
			{
				GetModel = new GetMauThietKeViewModel
				{
					LstObjModel = _repMauThietKe.RetrieveByID(dataTransfer.IntID)
				},
				EditModel = new EditMauThietKeViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

        public ThietKeWebViewModel RetrieveThietKeWebViewModel(DataTransferViewModel dataTransfer)
        {
            return new ThietKeWebViewModel
            {
                GetModel = new GetThietKeWebViewModel
                {
                    LstObjModel = _repThietKeWeb.SelectAll(),
                    TotalItem = _repThietKeWeb.GetTotalItem(),
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddThietKeWebViewModel
                {
                },
                EditModel = new EditThietKeWebViewModel
                {
                    ID = dataTransfer.IntID,
                },
                InfoText = dataTransfer.InfoText
            };
        }

        public KhachHangLamPhanMemViewModel RetrieveKhachHangLamPhanMemViewModel(DataTransferViewModel dataTransfer)
        {
            return new KhachHangLamPhanMemViewModel
            {
                GetModel = new GetKhachHangLamPhanMemViewModel
                {
                    LstObjModel = _repKhachHangLamPhanMem.SelectPaging(dataTransfer.CurrentPage, WebConfiguration.NumKhachHangLamPhanMemPerPage),
                    TotalItem = _repKhachHangLamPhanMem.GetTotalItem(),
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddKhachHangLamPhanMemViewModel
                {
                },
                EditModel = new EditKhachHangLamPhanMemViewModel
                {
                    ID = dataTransfer.IntID,
                },
                InfoText = dataTransfer.InfoText
            };
        }

        public KhachHangLamPhanMemViewModel RetrieveDetailOfKhachHangLamPhanMemViewModel(DataTransferViewModel dataTransfer)
        {
            return new KhachHangLamPhanMemViewModel
            {
                GetModel = new GetKhachHangLamPhanMemViewModel
                {
                    LstObjModel = _repKhachHangLamPhanMem.RetrieveByID(dataTransfer.IntID)
                },
                EditModel = new EditKhachHangLamPhanMemViewModel
                {
                    ID = dataTransfer.IntID,
                },
                InfoText = dataTransfer.InfoText
            };
        }
	}
}